package com.linwen.javase.desgin_pattern.BigTalkDesignPattenJAVACode._03装饰模式._5商品价格策略工厂;

/**
 * @ClassName CashReturnRebate
 * @Description TODO
 * @Author zero
 * @DATE 2023/7/10 10:55 PM
 * @Version 1.0
 */
public class CashReturnRebate extends CashSuper {
    private double moneyRebate = 1d;
    private double moneyCondition = 0d; //返利条件
    private double moneyReturn = 0d;    //返利值

    public CashReturnRebate(double moneyRebate,double moneyCondition,double moneyReturn){
        this.moneyRebate = moneyRebate;
        this.moneyCondition = moneyCondition;
        this.moneyReturn = moneyReturn;
    }

    @Override
    //先折扣，再返利
    public double acceptCash(double price,int num){
        double result = price * num * this.moneyRebate;
        if (moneyCondition>0 && result >= moneyCondition)
            result = result - Math.floor(result / moneyCondition) * moneyReturn;
        return result;
    }
}
